﻿$(document).ajaxStop($.unblockUI);

$("#user_receive_emails").click(
  function () {
      if ($("#user_receive_emails").is(':checked')) {
          $("#user_receive_emails").val("on");
          //$("#job_alert_selectors").show("slow");
      }
      else {
          $("#user_receive_emails").val("off");
          //$("#job_alert_selectors").hide("slow");
      }
  });

$("#forgot_password_submit").click(
  function () {
      var validator = $("#forgot_password_form").bind("invalid-form.validate", function () {
          
      }).validate({
          debug: true,
          errorElement: "em",
          errorPlacement: function(error, element) {
              error.appendTo(element.prev());
          },
          success: function(label) {
              
          },
          rules: {
              user_email: {
                  required: true,
                  email: true,
                  minlength: 7
              }
          },
          messages: {
          },
          submitHandler: function(form) {
              $.blockUI({ message: "<h2><img class='busyprocess' src='/files/themes/Astro/images/busy.gif'>Loading...</h2>" });
              AstroRecruitment.ForgotPassword('/__utility/ajax/candidate.ashx');
          }
      });
  });

  $("#signin_submit").click(
  function () {
      var validator = $("#signin_form").bind("invalid-form.validate", function () {

      }).validate({
          debug: true,
          errorElement: "em",
          errorPlacement: function (error, element) {
              error.appendTo(element.prev());
          },
          success: function (label) {

          },
          rules: {
              user_email: {
                  required: true,
                  email: true,
                  minlength: 7
              },
              user_password: {
                  required: true,
                  minlength: 4
              }
          },
          messages: {
          },
          submitHandler: function (form) {
              $.blockUI({ message: "<h2><img class='busyprocess' src='/files/themes/Astro/images/busy.gif'>Loading...</h2>" });
              AstroRecruitment.SignIn('/__utility/ajax/candidate.ashx');
          }
      });
  });

  $("#change_password_submit").click(
  function () {
      var validator = $("#change_password").bind("invalid-form.validate", function () {

      }).validate({
          debug: true,
          errorElement: "em",
          errorPlacement: function (error, element) {
              error.appendTo(element.prev());
          },
          success: function (label) {

          },
          rules: {
              user_current_password: {
                  required: true,
                  minlength: 4
              },
              user_password: {
                  required: true,
                  minlength: 4
              },
              user_password_confirmation: {
                  required: true,
                  equalTo: "#user_password"
              }
          },
          messages: {
          },
          submitHandler: function (form) {
              $.blockUI({ message: "<h2><img class='busyprocess' src='/files/themes/Astro/images/busy.gif'>Loading...</h2>" });
              AstroRecruitment.ChangePassword('/__utility/ajax/candidate.ashx');
          }
      });
  });

  $("#register_submit").click(
  function () {
      var validator = $("#register_form").bind("invalid-form.validate", function () {

      }).validate({
          debug: true,
          errorElement: "em",
          errorPlacement: function (error, element) {
              error.appendTo(element.prev());
          },
          success: function (label) {

          },
          rules: {
              user_email: {
                  required: true,
                  email: true,
                  minlength: 7
              },
              user_email_confirmation: {
                  equalTo: "#user_email"
              },
              user_telephone: {
                  required: true,
                  minlength: 6
              },
              user_password: {
                  required: true,
                  minlength: 4
              },
              user_password_confirmation: {
                  equalTo: "#user_password"
              }
          },
          messages: {
          },
          submitHandler: function (form) {
              $.blockUI({ message: "<h2><img class='busyprocess' src='/files/themes/Astro/images/busy.gif'>Loading...</h2>" });
              AstroRecruitment.Register('/__utility/ajax/candidate.ashx');
          }
      });
  });

  $("#user_submit").click(
  function () {
      var validator = $("#edit_user").bind("invalid-form.validate", function () {

      }).validate({
          debug: true,
          errorElement: "em",
          errorPlacement: function (error, element) {
              error.appendTo(element.prev());
          },
          success: function (label) {

          },
          rules: {
              user_email: {
                  required: true,
                  email: true,
                  minlength: 7
              },
              user_name: {
                  required: true,
                  minlength: 6
              },
              user_telephone: {
                  required: true,
                  minlength: 6
              }
          },
          messages: {
          },
          submitHandler: function (form) {
              $.blockUI({ message: "<h2><img class='busyprocess' src='/files/themes/Astro/images/busy.gif'>Loading...</h2>" });
              AstroRecruitment.EditAccount('/__utility/ajax/candidate.ashx');
          }
      });
  });